import Axios from "./AxiosHelper"

export class AllRequest {
    static async requestPost(_url, _params, _options) {
        return await Axios.post(_url, _params, _options ? _options : {})
    }
    /* 增 */
    static async login(_params) {/* 登录 */
        return await this.requestPost("user/login.php", _params)
    }
    static async register(_params) {/* 注册 */
        return await this.requestPost("user/createUser.php", _params)
    }
    static async addRole(_params) {/* 添加角色 */
        return await this.requestPost("role/createRole.php", _params)
    }
    static async addCategory(_params) {/* 添加分类 */
        return await this.requestPost("category/createCategory.php", _params)
    }
    static async addTb(_params) {/* 添加贴吧 */
        return await this.requestPost("tb/createTb.php", _params)
    }
    /* 查 */
    static async getHome() { // 获取首页设置
        return await this.requestPost("home/getHome.php")
    }
    static async getUsers(page = 1, size = 10) { // 获取用户
        return await this.requestPost("user/getUsers.php", { page, size })
    }
    static async getRoles(page = 1, size = 10) { //获取角色
        return await this.requestPost("role/getRoles.php", { page, size })
    }
    static async getCategories(page = 1, size = 10, pid = "0") { //获取分类
        return await this.requestPost("category/getCategories.php", { page, size, pid })
    }
    static async getTopCategoriesName(page = 1, size = 10, name = null) { //以分类名获取顶级分类
        return await this.requestPost("category/getTopCategoriesName.php", { page, size, name })
    }
    static async getTb(page = 1, size = 10, category = null) { //获取贴吧列表
        return await this.requestPost("tb/getTb.php", { page, size, category })
    }
    /* 删 */
    static async deleteUser(_params) {/* 删除用户 */
        return await this.requestPost("user/deleteUser.php", _params)
    }
    static async deleteRole(_params) {/* 删除角色 */
        return await this.requestPost("role/deleteRole.php", _params)
    }
    static async deleteCategory(_params) {/* 删除分类 */
        return await this.requestPost("category/deleteCategory.php", _params)
    }
}

